{% extends 'dashboard/layout.html' %}
{% load i18n %}
{% load thumbnail %}
{% load staticfiles %}
{% load sorting_tags %}
{% load render_table from django_tables2 %}

{% block body_class %}{{ block.super }} catalogue{% endblock %}

{% block title %}
    {% trans "Products" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li>
            <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
        </li>
        <li class="active">{% trans "Products" %}</li>
    </ul>
{% endblock %}

{% block header %}
    <div class="page-header action">
        <h1>{% trans "Products" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
    {% block create_product %}
        <div class="table-header">
            <h3><i class="icon-sitemap icon-large"></i> {% trans "Create new product" %}</h3>
        </div>
        <div class="well">
            <form action="{% url 'dashboard:catalogue-product-create' %}" method="get" class="form-inline">
                {% include "dashboard/partials/form_fields_inline.html" with form=productclass_form %}
                <button class="btn btn-primary" type="submit" data-loading-text="{% trans 'Submitting...' %}"><i class="icon-plus"></i> {% trans "New Product" %}</button>
            </form>
        </div>
    {% endblock %}

    {% block search_products %}
        <div class="table-header">
            <h3><i class="icon-search icon-large"></i>{% trans "Search Products" %}</h3>
        </div>
        <div class="well">
            <form method="get" class="form-inline">
                {% comment %}
                    Add the current query string to the search form so that the
                    sort order is not reset when searching.
                {% endcomment %}
                {% for name, value in request.GET.items %}
                    {% if name not in form.fields %}
                        <input type="hidden" name="{{ name }}" value="{{ value }}"/>
                    {% endif %}
                {% endfor %}

                {% include "dashboard/partials/form_fields_inline.html" with form=form %}
                <button type="submit" class="btn btn-primary" data-loading-text="{% trans 'Searching...' %}">{% trans "Search" %}</button>
            </form>
        </div>
    {% endblock %}

    {% if products %}
        {% block product_list %}
            <form method="post">
                {% csrf_token %}
                {% render_table products %}
            </form>
            <div class="modal fade" id="product-image-modal" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title"></h4>
                        </div>
                        <div class="modal-body text-center">
                            <img class="img-responsive center-block">
                        </div>
                    </div>
                </div>
            </div>
        {% endblock product_list %}
    {% else %}
        <p>{% trans "No products found." %}</p>
    {% endif %}

{% endblock dashboard_content %}

{% block onbodyload %}
    {{ block.super }}
    oscar.dashboard.product_lists.init();
{% endblock onbodyload %}
